<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
        <style>
            .container{
                width: 80%;
                height:300px;
                position: relative;
                border: 3px solid #aaa;
                margin: 0 auto;
            }
            .item{
                width: 100px;
                height: 100px;
                border-radius: 50%;
                background-color: brown;
                left: 0;
                top: 20px;
                position: absolute;
                animation: move 4s linear infinite ;
            }
            .line{
                height: 5px;
                width: calc(var(--w));
                left: 0;
                position: absolute;
                top: 200px;
                background-color: blue;
            }
            @keyframes move {
                50%{
                    transform: translateX(calc(var(--w)));
                }
            }
        </style>
	</head>
	<body>
        <div class="container">
            <div class="item"></div>
            <div class="line"></div>
        </div>
	</body>
    <script>
        const container=document.querySelector(".container");
        const w=container.clientWidth;
        container.style.setProperty('--w', w-100 +'px');
    </script>
</html>